package idiet.dao.hibernate;

import idiet.bean.CustomerPal;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("customerPalDao")
public class CustomerPalDao extends BaseDao {
	public CustomerPal getCustomerPalById(int palId){
		return (CustomerPal) this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerPal.class)
				.add(Restrictions.eq("id", palId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerPal> getCustomerPalsByCustomerPalName(String customerPalName){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerPal.class)
				.add(Restrictions.like("name",customerPalName))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerPal> getCustomerPals(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerPal.class)
				.list();
	}
	public void createCustomerPal(CustomerPal pal){
		this.sessionFactory
		.getCurrentSession()
		.save(pal);
	}
	public void updateCustomerPal(CustomerPal pal){
		this.sessionFactory
		.getCurrentSession()
		.update(pal);
	}
	public void deleteCustomerPal(CustomerPal pal){
		this.sessionFactory
		.getCurrentSession()
		.delete(pal);
	}
}
